<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */

class HRIS_M_attendance_statistic extends BZ_Model
{
	public $return_recursive;

	function __construct()
	{
		parent::__construct();

		$this->return_recursive = array();
	}


/**
 * @section HRIS::Attendance Statistic Model
 */

	/**
	 * @function viewlist_generate
	 * @description generate the specific viewlist for the attendance statistic RECURSIVELY!
	 */
	public function viewlist_generate($prm_dbase = 'db_default', $prm_where = array(), $prm_recursive_parent_id = 0, $prm_recursive_level = 0, $prm_recursive_delimiter = '&mdash;')
	{
		/**
		 * @description init the variables
		 */
		$use_db = $this->{$prm_dbase};

		/**
		 * @description get the company structure
		 */
		$structure_query = $use_db->get_where('hris_organization_company_structure', array_merge(array('parent_id' => $prm_recursive_parent_id), $prm_where));
		foreach ($structure_query->result() as $structure_rows)
		{
			$recursive_dash = str_repeat($prm_recursive_delimiter, $prm_recursive_level);
			/**
			 * @description get the employee data of that company structure
			 */
			$use_db->select('id, data__id, `number`, `fn_hris_employee_name_get`(data__id) as employee_name')
				->where(array('company__id' => $structure_rows->company__id, 'structure__id' => $structure_rows->id));
			$employee_query = $use_db->get('hris_employee_company');
			foreach ($employee_query->result() as $employee_rows	)
			{
				$edit_link = site_url($this->bz_segment['URL'] . '/form/' . $structure_rows->id . '/' . $employee_rows->data__id);
				$this->return_recursive[$employee_rows->data__id] = array
					(
						$recursive_dash . '<a href="#" onClick="js_common_link(\'' . $edit_link . '\')" title="' . $this->lang->line('tooltips_edit') . '">' . $employee_rows->number . '</a>'
						, $employee_rows->employee_name, $structure_rows->name
					);
			}

			/**
			 * @description is there any sub data?
			 */
			$use_db->select('count(1) as structure_sub_count')->where(array_merge(array('parent_id' => $structure_rows->id), $prm_where));
			$structure_sub_count_query = $use_db->get('hris_organization_company_structure');
			if ($structure_sub_count_query->row()->structure_sub_count > 0)
			{
				$this->viewlist_generate($prm_dbase, $prm_where, $structure_rows->id, $prm_recursive_level + 1, $prm_recursive_delimiter);
			}
		}


		return $this->return_recursive;
	}


}

/** End of file hris_m_attendance_statistic.php */
/** Location: ./biskitz_mpc/biskitz/models/admin/hris/hris_m_attendance_statistic.php */
